![]() |
PATH![]() |
![]() ![]() |
Most control statements are compound statements that contain other statements. For example, the following Tell statement is a compound statement that contains two If statements.
tell application "Finder"
if (exists folder "Reports" of disk "Hard Disk") then
set reportsToPrint to (count every file ¬
of folder "Reports" of disk "Hard Disk")
else
set reportsToPrint to 0
end if -- checking for any reports to print
-- If we found any reports, print them.
if reportsToPrint > 0 then
tell application "ReportWizard"
-- Statements to print the reports.
end tell
end if -- had some reports to print
end tell
Compound statements begin with one or more reserved words, such as tell in the example above, that identify the type of compound statement. The last line of a compound statement is always end , which can optionally include the word that begins the control statement.
Control statements can contain other control statements. For example, the Tell statement above contains two If statements, one of which in turn contains a Set command. Control statements that are contained within other control statements are sometimes called nested control statements.
All control statements can be compound statements. In addition, some control statements can be written as single statements. For example, the statement
if (x > y) then return x
if (x > y) then
return x
end if
You can use a simple statement only when you're controlling the execution of a single statement (such as return x in the previous example).